package controller;

import dao.TicketDao;
import  model.tickets;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class TicketController  extends HttpServlet {
    public TicketController() {
        super();
    }
@Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        request.setCharacterEncoding("UTF-8");
        String leaveTime;
        String leaveCity;
        String arriveCity;
        leaveTime = request.getParameter("time1");
        leaveCity = request.getParameter("city");
        arriveCity = request.getParameter("city2");

        System.out.println(leaveTime+leaveCity+arriveCity);
        try {
            String id = TicketDao.getidtickets(leaveCity, arriveCity, leaveTime);
            System.out.println("***1"+id);
            String GoTime = TicketDao.getgoTime(leaveCity, arriveCity, leaveTime);
            System.out.println("***2"+GoTime);
            String ArriveTime = TicketDao.getarriveTime(leaveCity, arriveCity, leaveTime);
            System.out.println("***3"+ArriveTime);
            request.setAttribute("id",id);
            request.setAttribute("GoTime",GoTime);
            request.setAttribute("ArriveTime",ArriveTime);
        } catch (Exception e) {
            e.printStackTrace();
        }
        request.getRequestDispatcher("/ticketSearch.jsp").forward(request,response);
    }
}
